package com.adapter.objectadpter;

/**
 * @author xuehu
 * @date 2021/1/26 9:39
 */

public class VoltageAdapter extends Voltage220V implements IVoltage5V {

    private Voltage220V voltage220V; //这里体现的是关联关系中的聚合关系

    public VoltageAdapter() {
    }

    //通过构造器,传入一个Voltage220V实例
    public VoltageAdapter(Voltage220V voltage220V) {
        this.voltage220V = voltage220V;
    }

    @Override
    public int output5V() {
        int dst = 0;
        if (null != voltage220V) {
            int src = voltage220V.output220V();//获取220V电压
            System.out.println("使用对象适配器,进行适配~~");
            dst = src / 44;
            System.out.println("适配完成,输出的电压为=" + dst);
        }
        return dst;
    }
}
